import { Component, OnInit } from '@angular/core';

import { MonitorProductComponentService } from './monitor.product.compoenent.service';

import { ProductBase } from '../../product/product.base';
import { Util } from '../../../utils/util';
import { ToastyService } from '../../../modules/ng2-toasty';

@Component({
  selector: 'monitor-product',
  templateUrl: './monitor.product.compoenent.html',
  styleUrls: ['./monitor.product.compoenent.css'],
  providers: [MonitorProductComponentService]
})


export class MonitorProductComponent extends ProductBase {

  constructor(public util: Util, public toastyService: ToastyService, public service: MonitorProductComponentService) {
    super(service, util, toastyService);
    this.getHttp(this.param);
  }
  // 参数
  param: any = {
    type: 1,
    start: 0,
    rows: 1000,
    sort: '',
    sortType: ''
  };

  p:number = 0;

  // ngOnInit(){

  //   // this.util.columnHiddenHandel();

  // }
  addView: boolean = false;
  add() {
    this.addView = !this.addView;
    if (this.addView == false) {
      this.getHttp(this.param);

    }
  }

  sortChange(sort) {
    console.log(sort);

    let _sort: string = sort.sort;

    let _sortType: string = sort.sortType;

    if (_sortType == 'desc') {

      this.vm.table.products.sort((a, b) => {
        return a[_sort] < b[_sort];
      });

    } else {

      this.vm.table.products.sort((a, b) => {
        return a[_sort] > b[_sort];
      });

    }

  }

    export() {


     let dim = ['date', 'numberId', 'title', 'picUrl', 'loc', 'propertyValue', 'brandName','catName', 'sellAmount','sellMoney','monthSellAmount','monthSellMoney', 'price', 'monthPrice', 'shopName', 'uid','shopType'];

    let dimText = ['时间', '宝贝Id', '宝贝标题', '宝贝图片链接', '地址', '属性', '品牌名','类目', '销售量','销售额','近30天销售量','近30天销售额', '价格', '近30天成交均价', '店铺名', '店铺id','店铺类型'];



    let fileName =  "全部监控宝贝";

    let data = this.util.jsonToArrry(this.vm.table.products,dim,dimText);

    this.util.export(data,fileName);


  }

  getHttp(param) {

    var res  = {"code":0,"msg":"成功","data":{"value":[{"date":"2017-12-03 00:00:00","numberId":"37159234393","title":"【正品联保】Beats URBEATS 2.0重低音降噪入耳式耳机魔音B耳塞式","picUrl":"//g-search3.alicdn.com/img/bao/uploaded/i4/i2/1974623778/TB1HecuapTM8KJjSZFlXXaO8FXa_!!0-item_pic.jpg","loc":"浙江杭州","propertyValue":"是否线控:是,品牌:Beats,耳机插头类型:直插型,套餐类型:官方标配,频响范围:20-20000Hz,耳机售后服务:全国联保,型号:URBEATS,耳机输出音源:随身视听,缆线长度:1.2M,阻抗:32Ω,耳机类型:有线,耳机类别:HIFI耳机,生产企业:美国苹果公司,适用音乐类型:摇滚金属重低音类型,插头直径:3.5mm,有无麦克风:带麦,兼容平台:ANDROID iOS,佩戴方式:入耳式,颜色分类:哑光黑 土豪银 玫瑰金色 土豪金 天空灰 紫色 深灰,保修期:12个月,灵敏度:108dB/mW","brandName":"beats","price":498.0,"monthPrice":498.0,"quantity":0,"monthSellAmount":2680,"monthSellMoney":1334640.0,"sellAmount":31,"sellMoney":15438.0,"category":"1205","catName":"数码/手机/家电--影音电器--耳机/耳麦","uid":"1974623778","shopName":"beats微先专卖店","shopType":"商城","publishTime":null}],"count":1}};

      this.vm.table.products = res.data.value;

      this.vm.table.count = res.data.count;

    
  }

}
